package com.ylz.sjzx.sio.core.group.model;

import com.alipay.remoting.rpc.protocol.UserProcessor;
import com.ylz.sjzx.sio.core.group.manager.GroupRpc;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 *
 */

public class RpcProperties {
    /**
     * 组服务名称
     */
    private String groupName;

    /**
     * 组角色
     */
    private String groupRole;
    /**
     * 默认1234
     */
    private Integer port;

    private String ip;

    private List<UserProcessor> rpcUserProcessors;

    /**
     * 判断是否本机服务
     *
     * @return
     */
    public Boolean ifLocalService(String addr) {
        String localAddr = this.getLocalAddr();
        return StringUtils.equals(localAddr, addr);
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getGroupRole() {
        return groupRole;
    }

    public void setGroupRole(String groupRole) {
        this.groupRole = groupRole;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }


    public String getLocalAddr() {
        return this.getAddr(GroupRpc.localRemotingProperties.ip, GroupRpc.localRemotingProperties.port);
    }

    public String getAddr(String ip, int port) {
        return new StringBuilder().append(ip).append(":").append(port).toString();
    }

    public List<UserProcessor> getRpcUserProcessors() {
        return rpcUserProcessors;
    }

    public void setRpcUserProcessors(List<UserProcessor> rpcUserProcessors) {
        this.rpcUserProcessors = rpcUserProcessors;
    }
}
